package com.ncp.servlet.order;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.order.ManageOrderBiz;
import com.ncp.model.entity.order.OrderBasic;

public class ViewOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		int userID = (Integer)request.getSession().getAttribute("userID");
		//取得所有订单信息
		ManageOrderBiz biz = new ManageOrderBiz();
		List<OrderBasic> orders = biz.getOrderBasics(userID);
		
		//取得待付款订单数量
		int notPayNum = biz.getOrderNumByStatus(userID, "WAIT_BUYER_PAY");
		//待发货数量
		int notSentNum = biz.getOrderNumByStatus(userID, "WAIT_SELLER_SEND_GOODS");
		//待确认收货数量
		int notConfirmNum = biz.getOrderNumByStatus(userID, "WAIT_BUYER_CONFIRM_GOODS");
		//交易成功数量
		int finishNum = biz.getOrderNumByStatus(userID, "TRADE_FINISHED");
		
		request.setAttribute("orders", orders);
		request.setAttribute("notPayNum", notPayNum);
		request.setAttribute("notSentNum", notSentNum);
		request.setAttribute("notConfirmNum", notConfirmNum);
		request.setAttribute("finishNum", finishNum);
		
		request.getRequestDispatcher("pages/order/vieworder.jsp").forward(request, response);
	}

}
